<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="供应商名称" prop="supplierName">
        <el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="评价" prop="state">
        <el-select v-model="queryParams.state">
          <el-option label="评价正常" value="1" />
          <el-option label="评价已失效" value="2" />
          <el-option label="未评价" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['supplier:supplier:base:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['supplier:supplier:base:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['supplier:supplier:base:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['supplier:supplier:base:export']">导出</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="printBox"
          v-hasPermi="['supplier:supplier:base:print']"
          >打印</el-button
        >
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table @selection-change="handleSelectionChange" border fit v-loading="loading" :data="dataList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" />
      <el-table-column show-overflow-tooltip label="评价情况" min-width="100">
        <template slot-scope="scope">
          <!-- 评价状态 1.评价正常 2.评价失效 3.未评 -->
          <el-tag size="mini" :type="scope.row.state == 3
              ? 'info'
              : scope.row.state == 2
                ? 'danger'
                : 'success'
            ">{{
    scope.row.state == 3
    ? "未评价"
    : scope.row.state == 2
      ? "评价失效"
      : "评价正常"
  }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column min-width="200" label="服务商/供应商名称" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-link @click="handleDetail(scope.row)" type="primary">{{
            scope.row.supplierName
          }}</el-link>
        </template>
      </el-table-column>
      <el-table-column min-width="150" label="供应商类型" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_supplier_type" :value="scope.row.supplierType" />
        </template>
      </el-table-column>

      <el-table-column :show-overflow-tooltip="true" width="120" label="手机号" prop="mobilePhone" />

      <el-table-column :show-overflow-tooltip="true" width="120" label="电话" prop="phone" />
      <el-table-column :show-overflow-tooltip="true" min-width="200" label="地址" prop="address" />

      <el-table-column :show-overflow-tooltip="true" min-width="200" label="邮编" prop="zipCode" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" v-hasPermi="['supplier:supplier:base:info']"
            @click="handleDetail(scope.row)">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" v-hasPermi="['supplier:supplier:base:point']"
            @click="handlePoint(scope.row)">供应商服务评价</el-button>

          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['supplier:supplier:base:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['supplier:supplier:base:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 打印模板位置 -->
    <PrintBox :printRow="printList" id="printBox">
      <template slot="title" slot-scope="scope">
        <div style="margin-bottom: 20px">供应商服务评价表 STET/B/06-3</div>
      </template>
      <template slot-scope="scope">
        <!-- 表格  class  table-page  必须-->
        <table style="border-collapse: collapse" border="1" cellspacing="0" class="table-page" :isVertical="false">
          <tr class="tr-height">
            <td style="width: 50mm">供应商</td>
            <td colspan="3">
              <div style="display: flex; align-items: center">
                <div style="
                    display: flex;
                    align-items: center;
                    width: 30mm;
                    margin-left: 10mm;
                  ">
                  <input :checked="scope.item.supplierType == 1" type="checkbox" />设备生产厂家
                </div>
                <div style="
                    display: flex;
                    align-items: center;
                    width: 30mm;
                    margin-left: 10mm;
                  ">
                  <input type="checkbox" :checked="scope.item.supplierType == 2" />服务生产厂家
                </div>
              </div>
            </td>
          </tr>
          <tr class="tr-height">
            <td>地址</td>
            <td style="width: 80mm">{{ scope.item.address }}</td>
            <td style="width: 40mm">电话</td>
            <td style="width: 80mm">{{ scope.item.phone }}</td>
          </tr>
          <tr class="tr-height">
            <td>邮编</td>
            <td>{{ scope.item.zipCode }}</td>
            <td>传真</td>
            <td>{{ scope.item.fax }}</td>
          </tr>
          <tr class="tr-height">
            <td>供应商联系人</td>
            <td>{{ scope.item.person }}</td>
            <td>手机</td>
            <td>{{ scope.item.mobilePhone }}</td>
          </tr>
          <tr class="tr-height">
            <td>
              <div>供应商商品名称</div>
              <div>（提供服务名称）</div>
            </td>
            <td colspan="3">{{ scope.item.supplierName }}</td>
          </tr>
          <tr class="tr-height">
            <td>供方响应情况</td>
            <td colspan="3">{{ scope.item.response }}</td>
          </tr>
          <tr class="tr-height">
            <td>
              <div>供应商</div>
              <div>资质证书</div>
            </td>
            <td colspan="3">{{ getFileName(scope.item.qualificationsUrl) }}</td>
          </tr>
          <tr class="tr-height">
            <td>供应商<br />质保书</td>
            <td colspan="3">{{ getFileName(scope.item.qualityUrl) }}</td>
          </tr>
          <tr>
            <td>公司联系人<br />评价意见</td>
            <td colspan="3" style="position: relative">
              <div style="width: 500px; position: absolute; text-align: left">
                {{ scope.item.opinion }}
              </div>
              <div style="
                  display: flex;
                  justify-content: flex-end;
                  text-align: left;
                  margin-top: 30px;
                ">
                <div style="width: 40mm; position: relative">
                  签名：<img style="width: 60px; position: absolute; top: -30px"
                    :src="$VUE_APP_IMG_API + scope.item.esign" />
                </div>
                <div style="width: 40mm">
                  日期：{{ checkHistoryNode(scope, "start").endTime }}
                </div>
              </div>
            </td>
          </tr>
          <tr style="height: 40mm">
            <td>技术质量部门<br />意见</td>
            <td colspan="3" style="position: relative">
              <div>
                <div style="display: flex; align-items: center">
                  <input type="checkbox" :checked="checkHistoryNodeComment(scope, 'jszlbmyj').type == 1
                    " />服务商/供应商价格、资质等满足要求
                </div>
                <div style="display: flex; align-items: center">
                  <input type="checkbox" :checked="checkHistoryNodeComment(scope, 'jszlbmyj').type == 2 ||
                    checkHistoryNodeComment(scope, 'jszlbmyj').type == 3
                    " />服务商/供应商价格、资质等不满足要求
                </div>
              </div>
              <div style="
                  position: absolute;
                  top: 70px;
                  left: 10px;
                  text-align: left;
                ">
                <template v-if="CheckApprove(scope, 'jszlbmyj').ShowMessage">
                  {{ CheckApprove(scope, "jszlbmyj").MessageText }}
                </template>
              </div>
              <div style="
                  display: flex;
                  justify-content: flex-end;
                  text-align: left;
                  margin-top: 30px;
                ">
                <div style="width: 40mm; position: relative">
                  部门负责人：
                  <template v-if="CheckApprove(scope, 'jszlbmyj').ShowImg">
                    <img style="width: 80px; position: absolute; top: -10px"
                      :src="CheckApprove(scope, 'jszlbmyj').ApproveImg" />
                  </template>
                </div>
                <div style="width: 40mm">
                  日期：{{ checkHistoryNode(scope, "jszlbmyj").endTime }}
                </div>
              </div>
            </td>
          </tr>
          <tr style="height: 40mm">
            <td>审批意见</td>
            <td colspan="3" style="position: relative">
              <div style="
                  position: absolute;
                  top: 70px;
                  left: 10px;
                  text-align: left;
                ">
                <template v-if="CheckApprove(scope, 'jsfzr').ShowMessage">
                  {{ CheckApprove(scope, "jsfzr").MessageText }}
                </template>
              </div>
              <div style="display: flex; align-items: center">
                <div style="display: flex; align-items: center; width: 30mm">
                  <input type="checkbox" :checked="checkHistoryNodeComment(scope, 'jsfzr').type == 1" />同意
                </div>
                <div style="
                    display: flex;
                    align-items: center;
                    width: 30mm;
                    margin-left: 10mm;
                  ">
                  <input type="checkbox" :checked="checkHistoryNodeComment(scope, 'jsfzr').type == 2 ||
                    checkHistoryNodeComment(scope, 'jsfzr').type == 3
                    " />不同意
                </div>
              </div>
              <div style="
                  display: flex;
                  justify-content: flex-end;
                  text-align: left;
                  margin-top: 60px;
                ">
                <div style="width: 40mm; position: relative">
                  技术负责人：<template v-if="CheckApprove(scope, 'jsfzr').ShowImg">
                    <img style="width: 80px; position: absolute; top: -10px"
                      :src="CheckApprove(scope, 'jsfzr').ApproveImg" />
                  </template>
                </div>
                <div style="width: 40mm">
                  日期：{{ checkHistoryNode(scope, "jsfzr").endTime }}
                </div>
              </div>
            </td>
          </tr>
          <tr style="height: 40mm">
            <td>管理层意见</td>

            <td colspan="3" style="position: relative">
              <div style="
                  position: absolute;
                  top: 70px;
                  left: 10px;
                  text-align: left;
                ">
                <template v-if="CheckApprove(scope, 'glcyj').ShowMessage">
                  {{ CheckApprove(scope, "glcyj").MessageText }}
                </template>
              </div>
              <div style="display: flex; align-items: center">
                <div style="display: flex; align-items: center; width: 60mm">
                  <input type="checkbox" :checked="checkHistoryNodeComment(scope, 'glcyj').type == 1" />同意采用该服务商/供应商
                </div>
                <div style="
                    display: flex;
                    align-items: center;
                    width: 60mm;
                    margin-left: 10mm;
                  ">
                  <input type="checkbox" :checked="checkHistoryNodeComment(scope, 'glcyj').type == 2 ||
                    checkHistoryNodeComment(scope, 'glcyj').type == 3
                    " />不同意采用该服务商/供应商
                </div>
              </div>
              <div style="
                  display: flex;
                  justify-content: flex-end;
                  text-align: left;
                  margin-top: 60px;
                ">
                <div style="width: 40mm; position: relative">
                  总经理：<template v-if="CheckApprove(scope, 'glcyj').ShowImg">
                    <img style="width: 80px; position: absolute; top: -10px"
                      :src="CheckApprove(scope, 'glcyj').ApproveImg" />
                  </template>
                </div>
                <div style="width: 40mm">
                  日期：{{ checkHistoryNode(scope, "glcyj").endTime }}
                </div>
              </div>
            </td>
          </tr>
        </table>
        <!-- 底部信息位置 -->
        <div class="page-bottom" style="page-break-after: always">
          <div class="desc">注：本表格自2021年6月1日起生效</div>
        </div>
      </template>
    </PrintBox>
  </div>
</template>

<script>
import printStyle from "@/utils/print.js";

import {
  listsupplier,
  delsupplier,
  effectSupplier,
} from "@/api/supplier/SupplierBase.js";

export default {
  name: "SupplierBase",
  dicts: ["sys_supplier_type"],
  data() {
    return {
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      dataList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        supplierName: undefined,
        operUserId: undefined,
        phone: undefined,
        checkDate: null,
      },
      // 日期范围
      dateRange: [],

      userList: [],
      deptOptions: [],
      infos: [],
      printList: [],
    };
  },
  created() {
    const str = sessionStorage.getItem('queryParams');
    console.log(str);
    if (str) {
      this.queryParams = JSON.parse(str)
      setTimeout(() => {
        sessionStorage.removeItem('queryParams');
      }, 500)
    }
    this.getList();
  },
  methods: {
    printBox() {
      //infos  勾选的数据 如果有勾选就打印勾选。
      if (this.infos.length) {
        this.printList = this.infos;
      } else {
        //反之打印当前整个列表
        this.printList = this.dataList;
      }
      setTimeout(() => {
        document.title = "供应商服务评价表 STET/B/06-3";

        this.$print({
          printable: "printBox", //打印区域id
          type: "html", //打印类型是html
          scanStyles: false,
          targetStyles: ["*"],
          style: this.workStyle(),
          onPrintDialogClose: () => {
            document.title = process.env.VUE_APP_TITLE;
          },
        });
      }, 500);
    },
    // 可以自定义样式  printStyle 是公共样式 切勿私自修改
    workStyle() {
      return `${printStyle}
      .tr-height{
        height:15mm
      }
        table,
        table tr th,
        table tr td {
          padding: 4px;
        }
        .desc{
        text-align: left; font-size: 12px; margin-top: 10px
      }
            .df {
                display: flex;
              }
      `;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.supplierBaseId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.infos = selection;
    },
    handleStatusChange(row) {
      let text = row.effectStatus === "1" ? "启用" : "禁用";
      this.$modal
        .confirm('确认要"' + text + '""' + row.supplierName + '"供应商吗？')
        .then(function () {
          return effectSupplier(row.supplierBaseId, row.effectStatus);
        })
        .then(() => {
          this.$modal.msgSuccess(text + "成功");
        })
        .catch(function (e) {
          row.effectStatus = row.effectStatus === "0" ? "1" : "0";
        });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      sessionStorage.setItem('queryParams', JSON.stringify(this.queryParams));
      const configId = row.supplierBaseId || this.ids;
      this.$router.push("./supplierBaseInfo?isEdit=true&id=" + configId);
    },
    handlePoint(row) {
      sessionStorage.setItem('queryParams', JSON.stringify(this.queryParams));
      this.$router.push("./addSupplier?idBase=" + row.supplierBaseId);
      // this.$router.push("./supplier?idBase=" + row.supplierBaseId);

      //
    },
    handleDetail(row) {
      sessionStorage.setItem('queryParams', JSON.stringify(this.queryParams));
      this.$router.push(
        "./supplierBaseInfo?isInfo=true&id=" + row.supplierBaseId
      );
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const configId = row.supplierBaseId || this.ids;
      let name = this.checkRow(
        configId,
        this.dataList,
        "supplierBaseId",
        "DELETE",
        "supplierName"
      );
      this.$modal
        .confirm('是否确认删除供应商名称为"' + name + '"的数据项？')
        .then(function () {
          return delsupplier(configId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    handleAdd() {
      this.$router.push("./supplierBaseInfo");
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listsupplier(
        this.addDateRangeTime(
          this.queryParams,
          this.dateRange,
          "startEndDate",
          "endEndDate"
        )
      ).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleExport() {
      this.download(
        "system/SupplierBase/export",
        {
          ...this.queryParams,
        },
        `供应商记录表_${this.parseTime(
          new Date().getTime(),
          "{y}-{m}-{d}"
        )}.xlsx`
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 获取文件名称
    getFileName(name) {
      // 如果是url那么取最后的名字 如果不是直接返回
      if (name.lastIndexOf("/") > -1) {
        return name.slice(name.lastIndexOf("/") + 1);
      } else {
        return name;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  img {
    width: 100%;
  }
}
</style>
